home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr24 / steprat1.zip / STEPRAT1.ASM next >
Assembly Source File  |  1993-05-22  |  6KB  |  226 lines

  1. page    60,132
  2.  
  3. title    STEPRATE  A program to change the step rate of Floppy drives
  4. ;
  5. ; Before I receive any flames on the goodness of the following code, I
  6. ; would like to say that I find the 8088 destruction set disgusting.  I
  7. ; would have written this program in C (or some language which shelters
  8. ; me from the architecture but I have an inherent abhorance of 32K programs
  9. ; which do something as simple as this.
  10. ; If you do not like the way I wrote it, then feel free to rewrite it.
  11. ; In case you have not guessed, DEMENTed REGISTERS and I do not get along
  12. ; together.
  13. ;
  14. ;v1.1 Toad Hall Major Rewrite, 7 Feb 89
  15. ; - Original author unknown (snarfed from SEMPER BBS, Fayetteville NC)
  16. ; - Retabified to "normal" col-9 tabs
  17. ; - Changed some MASM-reserved labels (like loop)
  18. ; - Rewrote to .COM file format
  19. ; - MAJOR rewrites of command line processing,
  20. ;   Ascii to Binary conversion of step rate characters,
  21. ;   displaying selected rate
  22. ; - Now, if you enter with no cmdline parms, it will display the current
  23. ;   floppy disk step rate (with no change).
  24. ; - I'm trying VERY hard not to comment on the author's code
  25. ;   (given his disclaimer above).
  26. ;
  27. ;David Kirschbaum
  28. ;Toad Hall
  29.  
  30. CR    equ    0Dh        ;carriage return character
  31. LF    equ    0Ah        ;line feed character
  32.  
  33. Page0    segment at 0        ;v1.1
  34.     org    78H        ;Floppy disk steprate pointer
  35. stepptr    dw    ?
  36.  
  37. Page0    ENDS
  38.  
  39. ;********************************************
  40. CSEG    segment public para 'CODE'    ;v1.1
  41.     ASSUME    CS:CSEG,DS:CSEG,ES:CSEG    ;v1.1
  42.  
  43.     org    80h
  44. count    db    ?            ;PSP command line length
  45.  
  46.     org    100H            ;normal .COM start    v1.1
  47.  
  48. StepRate    proc    near        ;v1.1
  49.     jmp    Start            ;skip over data        v1.1
  50.  
  51. sm    db    'Floppy drive steprate: ',CR,LF
  52.     db    'current: '
  53. oldrate    dw    '%%'            ;space for old rate
  54.     db    ', new: '
  55. newrate    dw    '%%'            ;space for new rate
  56.     db    CR,LF,'$'
  57.  
  58. rateTable label    word            ;v1.1
  59.     db    ' 3'
  60.     db    ' 6'
  61.     db    ' 9'
  62.     db    '12'
  63.  
  64. stepTable label    byte            ;v1.1
  65.     db    0e0h            ;3 ms step rate
  66.     db    0d0h            ;6 ms step rate
  67.     db    0c0h            ;9 ms step rate
  68.     db    0b0h            ;12 ms step rate
  69.  
  70.  
  71. minval  db    '3, 6, 9 or 12 are the only recognized step rates.'
  72.     db    CR,LF,'$'
  73.  
  74. StepRate    endp            ;v1.1
  75.  
  76.  
  77. Start    proc    near            ;v1.1
  78.  
  79. ; see if a step rate entered from the keyboard
  80.  
  81. ;v1.1 Gonna use SI and CX to scan the PSP command line for a step rate.
  82.  
  83.     mov    si,offset count        ;point to PSP command line
  84.     lodsb                ;snarf cmdline length byte
  85.     xor    ah,ah            ;clear msb
  86.     mov    cx,ax            ;CX is the counter
  87.     jcxz    NoInput            ;no input
  88.  
  89.     xor    dx,dx            ;set 'accumulator' to 0
  90. Loop1:
  91.     lodsb                ;next cmdline char
  92.     cmp    al,' '
  93.     jz    Aloop            ;step past spaces
  94.  
  95.     cmp    al,'0'
  96.     jb    NoInput            ;bad, not a digit
  97.     cmp    al,'9'
  98.     ja    NoInput            ;bad, not a digit
  99.  
  100.     sub    al,'0'            ;deasciify
  101.     shl    dl,1            ;*2
  102.     mov    dh,dl            ;save that *2 value in DH
  103.     shl    dl,1            ;*4
  104.     shl    dl,1            ;*8
  105.     add    dl,dh            ;plus the *2 = *10
  106.     add    dl,al            ;plus the new value
  107.  
  108. Aloop:
  109.     loop    Loop1            ;do it for all chars
  110.  
  111. ;Binary step rate 3,6,9, or 12 should be in DL
  112. ;Divide by 3 to get a table offset
  113. ;Any remainder, of course, means it was NOT a legal value.
  114.  
  115.     xor    dh,dh            ;clear DX's msb
  116.     mov    ax,3            ;divisor
  117.     xchg    dx,ax            ;AL=step rate, DL=3
  118.     div    dl            ;dividend in AL, remainder in AH
  119.     or    ah,ah            ;any remainder?
  120.     jnz    Not_Valid        ;yep, invalid, help and terminate
  121.  
  122. ;AL now has 1..4
  123.     dec    ax            ;adjust for table offset
  124.     cmp    ax,dx            ;<= 3 max value?
  125.     jbe    Valid            ;yep, so it's [0..3], legal
  126.  
  127. ;v1.1 Come here if illegal steprate entry
  128. Not_Valid:
  129.     mov    dx, offset minval    ;'3,6,9,12 are only recognized rates'
  130.  
  131. ;v1.1 Enter here with a terminating message
  132. Msg_Term:
  133.     mov    ah,9
  134.     int    21h
  135.     mov    ax,4C00H        ;terminate, errorlevel 0
  136.     int    21H
  137.  
  138. ;A nonvalid step rate number has been entered.
  139. ;Clear DX (to show no legal step rate),
  140. ;Skip down to read the current BIOS disk step rate
  141.  
  142. NoInput:
  143.     xor    dx,dx
  144.     jmp    short No_Rate
  145.  
  146. ; a valid number has been entered, change the step rate to it
  147. ;AX has [3..0], the "inverted" steprate table offset
  148. Valid:
  149.     add    ax,offset stepTable    ;add in step table base
  150.     mov    bx,ax            ;BX = 0..3
  151.     mov    dl,[bx]            ;DL = table step rate
  152.  
  153. No_Rate:
  154.     xor    ax,ax            ;handy 0            v1.1
  155.     mov    DS,ax            ;DS=page 0
  156.     ASSUME    DS:Page0        ;v1.1
  157.  
  158.     mov    ax,stepptr        ;get the step rate pointer    v1.1
  159.                     ; at 0:78H            v1.1
  160.     mov    bx,ax            ;into the bx register
  161.     mov    al,[bx]            ;now get the present step rate
  162.  
  163.     mov    dh,al            ;save for later display        v1.1
  164.     or    dl,dl            ;any new rate to set?        v1.1
  165.     jnz    New_Rate        ;yep                v1.1
  166.      mov    dl,dh            ;push current step rate into DL    v1.1
  167.      jmp    short No_Change        ;skip                v1.1
  168.  
  169. New_Rate:
  170.     and    al,0fh            ;remove the old step rate
  171.     or    al,dl            ;put in the new step rate
  172.     mov    [bx],al            ;and put it back where it goes
  173.  
  174.     xor    ah,ah            ;Now call on the BIOS to    v1.1
  175.     int    13h            ;reload the set floppy disk controller
  176.  
  177. No_Change:
  178.     mov    ax,CS
  179.     mov    DS,ax            ;reset DS            v1.1
  180.     ASSUME    DS:CSEG
  181.  
  182. ; A new step rate has been successfully loaded,
  183. ; or we're just returning the current rate.
  184. ; Let's tell 'em what they got.
  185. ; DH=old steprate, DL=new steprate (if changed, else old steprate)
  186. ;v1.1 all new code
  187.  
  188.     mov    al,dh            ;old steprate
  189.     and    al,0F0H            ;mask out all but steprate
  190.     call    Get_Rate        ;get Ascii rate into AX
  191.     mov    oldrate,ax        ;stuff in message
  192.  
  193.     mov    al,dl            ;new steprate
  194.     call    Get_Rate        ;get Ascii rate into AX
  195.     mov    newrate,ax        ;stuff in message
  196.  
  197.     mov    dx,offset sm        ;'Rate set to ...'
  198.     jmp    Msg_Term        ;display msg, terminate
  199.  
  200. Start    endp
  201.  
  202. ;v1.1 Enter with AL=disk rate parameter (0B0H .. 0E0H)
  203. ;Exit with AX containing Ascii rate digits ' 3'..'12'
  204.  
  205. Get_Rate    proc    near        ;v1.1
  206.     xor    ah,ah            ;clear msb
  207.     sub    al,0B0H            ;- highest rate (12ms)
  208.                     ;AL is now 0 (12ms), 1 (9ms),
  209.                     ; 2 (6ms), or 3 (3ms)
  210.     mov    cl,4            ;shift bits 5..8 to 1..4
  211.     shr    ax,cl            ;shift, AL now [0..3]
  212.  
  213.     mov    bx,ax            ;keep in BX
  214.     mov    al,3            ;max value
  215.     sub    al,bl            ;- rate
  216.     shl    ax,1            ;*2 for words
  217.     add    ax,offset rateTable    ;' 3'..'12'
  218.     mov    bx,ax            ;into BX
  219.  
  220.     mov    ax,[bx]            ;get rate
  221.     ret
  222. Get_Rate    endp
  223.  
  224. CSEG    ENDS
  225.     end    StepRate
  226.